// components/rankingtop/index.js
const app = getApp()
Component({
  /**
   * 组件的属性列表
   */
  properties: {
         // 这里定义了id属性，属性值可以在组件使用时指定
    selectid: {
      type: Number,
      value: 0
    },
    baseimgaeUrl:{
      type:String,
      value:""
    },
    topsetoff:{
      type: Number,
      value: 5,
      observer: function (newVal, oldVal) {

       // this._topsetoffpropertyChange(newVal, oldVal);

      } // 属性被改变时执行的函数（可选），也可以写成在methods段中定义的方法名字符串, 如：'_propertyChange'
    },
    rankingleaders: {
      type: Object,
      value: undefined,
      observer: function (newVal, oldVal) {

        this._rankingleaderspropertyChange(newVal, oldVal);

      } // 属性被改变时执行的函数（可选），也可以写成在methods段中定义的方法名字符串, 如：'_propertyChange'

    },
  },

  /**
   * 组件的初始数据
   */
  data: {
    staticUrl: app.globalData.staticUrl,
    currentTab:0,
    currentpageheight:0,
    to5rankingleaders:[]
  },

  /**
   * 组件的方法列表
   */
  methods: {
        //打开playerscorecinfo 页面 
    _openplayerinfo(e) {
      this.setData({
        selectplayerid: e.currentTarget.dataset.id,
        teamorplayer: 0
      });
      let id = this.data.selectplayerid;
      // 微信小程序中是通过triggerEvent来给父组件传递信息的
      this.triggerEvent('_openplayerinfo', {
        selectid: id
      }) // 将参数的形式传递给父组件

    },


   filltopleaders:function(newVal){
     if(newVal == undefined || newVal== null){
       newVal = this.data.rankingleaders;
     }
    var that = this;
    var  top5leader = [];
    var topindex = 0;
    for(var index=0;index<newVal.length;index++){
      if(index>=this.properties.topsetoff){
        break;
      }
      top5leader.push(newVal[index]);
    }
    that.setData({
      to5rankingleaders: top5leader
    });
   },

    _rankingleaderspropertyChange: function (newVal, oldVal) {
     
      var that = this;
     
     if(newVal==undefined || newVal== null || newVal.lenght<=0){
      
     }
      else{
       that.filltopleaders(newVal);
      }
      console.log(that.data.to5rankingleaders);
    },

    _matchleaderspropertyChange: function (newVal, oldVal) {
      this.fillheight();

    },

    ///填充swiper的高度，它不能自适应
    fillheight: function () {
      
     
    },

    //  tab切换逻辑
    swichNav: function (e) {
      var that = this;
      if (that.data.currentTab === e.target.dataset.current) {

        return false;
      } else {
        that.setData({
          currentTab: e.target.dataset.current
        })

        that.fillheight();
      }
    },

    bindChange: function (e) {
      var that = this;
      that.setData({
        currentTab: e.detail.current
      });
      that.fillheight();
    },
  }
})
